<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddTotalPriceToOrdersTable extends Migration
{
    public function up()
    {
        Schema::table('orders', function (Blueprint $table) {
            // 1. 先删除原有外键
            $table->dropForeign(['wechat_user_id']);
            // 2. 重命名字段
            $table->renameColumn('wechat_user_id', 'wechat_service_account_user_id');
        });

        Schema::table('orders', function (Blueprint $table) {
            // 3. 新增正确的外键
            $table->foreign('wechat_service_account_user_id')
                ->references('id')->on('wechat_service_account_users');
        });
    }

    public function down()
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->dropForeign(['wechat_service_account_user_id']);
            $table->renameColumn('wechat_service_account_user_id', 'wechat_user_id');
            $table->foreign('wechat_user_id')->references('id')->on('wechat_users');
        });
    }
} 